package com.yunwushanhe.document.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.yunwushanhe.document.handler.LoginHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 云雾山河
 * target mvc的配置类
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    //视图解析器
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/register.html").setViewName("register");
        registry.addViewController("/retrieve.html").setViewName("retrieve");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/",
                        "/login.html","/register.html","/retrieve.html","/document/users/login","/document/users/in",
                        "/document/users","/document/users/retrieve", "/document/users/send/*","/document/users/send2/*",
                        "/imgs/**","/js/**","/plugins/**","/css/**");//"/css/*","/js/**","/img/**","/plugins/**"
    }

    // 这里是在配置拦截器（和分页功能相关的）
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return interceptor;
    }

}
